﻿using System;
using System.Collections.Generic;
using System.Text;
using ZLDC.Common.Estate;
using System.Data;

namespace ZLDC.Topo.BLL.Estate
{
     public class HousingInformBLL
    {
                                    public static string p_housingInform_save(int ID, int housingId, string reason, string advise, int informDeptId, string informDept, int informUserId, string informUser, int dDeptId, string dDept, int dUserId, string dUser, string dView, string dResult, int dltFlag, int isValid)
         {
             string outmsg = "";
             int newid = 0;

             using (_Database db = new _Database("estate"))
             {
                 ZLDC.DAL.Estate.HousingInformDAL.p_housingInform_save(ID, housingId, reason, advise, informDeptId, informDept, informUserId, informUser, dDeptId, dDept, dUserId, dUser, dView, dResult, dltFlag, isValid, out outmsg, out newid, db);
             }

             return outmsg;
         
         }
                                    public static string p_housingInform_list_table(int page, int pagesize, int housingId, int isValid,int deptid,string IdList,string rolename,string duserid)
         {
             DataTable dt = null;
             int total = 0;                        int pageall = 0;         
             using (_Database db = new _Database("estate"))
             {
                 dt = ZLDC.DAL.Estate.HousingInformDAL.p_housingInform_list_table(page, pagesize, housingId,isValid,deptid,IdList,rolename,duserid, ref total, db);
             }

             pageall = _Utility.GetPageAll(pagesize, total);      
             _Json json = new _Json(dt, "yyyy-MM-dd HH:mm:ss");

             return "{page:{currentpage:'" + page + "',pagesize:'" + pagesize + "',total:'" + total + "',pageall:'" + pageall + "'},record:" + json.ToJson() + "}";

         }
                                    public static string p_housingInform_update(int ID, int dDeptId, string dDept, int dUserId, string dUser, string dView, string dResult, int isValid)
         {
             string outmsg = "";
             using(_Database db=new _Database("estate"))
             {
                 ZLDC.DAL.Estate.HousingInformDAL.p_housingInform_update(ID, dDeptId, dDept, dUserId, dUser, dView, dResult, isValid, out outmsg, db);
             }
             return outmsg;
         }
                                    public static string p_housingInform_updateisValid(int id, int isValid) 
         {
             string outmsg = "";
             string userId = _Utility.GetInfoBySession().m_sUserID;
             string deptId = _Utility.GetInfoBySession().m_sDeptID;
             string deptName = _Utility.GetInfoBySession().m_sDeptName;
             string userName = _Utility.GetInfoBySession().m_sUserName;
             using (_Database db = new _Database("estate")) 
             {
                 ZLDC.DAL.Estate.HousingInformDAL.p_housingInform_updateisValid(id, isValid, deptId, deptName, userId, userName, out outmsg, db);
             }
             return outmsg;
         }
                  public static string p_housingInform_updateisResult(int ID, int dDeptId, string dDept, int dUserId, string duser, string dResult, int isValid)
         {
             string outmsg = "";
             using (_Database db = new _Database("estate")) 
             {
                 ZLDC.DAL.Estate.HousingInformDAL.p_housingInform_updateisResult(ID, dDeptId, dDept, dUserId, duser, dResult, isValid, out outmsg, db);
             }
             return outmsg;
         }
                      public static string p_housingInform_ResultList_table(int page, int pagesize, int isValid, string dResult, string IdList,string DeptName,string starttime,string endtime)
         {
             DataTable dt = null;
             int total = 0;                        int pageall = 0;         
             using (_Database db = new _Database("estate"))
             {
                 dt = ZLDC.DAL.Estate.HousingInformDAL.p_housingInform_ResultList_table(page, pagesize, isValid, dResult, IdList,DeptName,starttime,endtime, ref total, db);
             }

             pageall = _Utility.GetPageAll(pagesize, total);      
             _Json json = new _Json(dt, "yyyy-MM-dd HH:mm:ss");
             return "{page:{currentpage:'" + page + "',pagesize:'" + pagesize + "',total:'" + total + "',pageall:'" + pageall + "'},record:" + json.ToJson() + "}";

         }
                  public static string p_housing_updateisValid(int ID, string advise)
         {
             string outmsg = "";
             int newid = 0;
             using (_Database db = new _Database("estate"))
             {
                 ZLDC.DAL.Estate.HousingInformDAL.p_housing_updateisValid(ID,advise, out outmsg, db);
             }
             if (outmsg == "更新成功") 
             {  
                                  int hid=ZLDC.DAL.Estate.HousingInformDAL.GetHousingIDById(ID);
                 using (_Database db=new _Database("estate")){
                     ZLDC.DAL.Estate.HousingFollowDAL.p_housingFollow_save(0, hid, "", 0, "", 0, "", "举报处理：" + advise + "", 0, "",out outmsg,out newid,db);
                 
                 }
                 outmsg = "更新成功";
             }
             return outmsg;
         }
    }
}
